package com.rainsoft.center.isec.frame.handler;

import com.rainsoft.center.isec.stream.library.entity.hbase.BaseLibEntity;
import org.apache.spark.api.java.JavaRDD;

/**
 * @Name com.rainsoft.center.isec.frame.Context
 * @Description
 * @Author Elwyn
 * @Version 2017/12/8
 * @Copyright 上海云辰信息科技有限公司
 **/
public abstract class AJavaRDDHandler<T extends BaseLibEntity> {

	private AJavaRDDHandler<T> next;


	public AJavaRDDHandler<T> setNext(AJavaRDDHandler<T> next) {
		this.next = next;
		return next;
	}

	public final void support(JavaRDD<T> javaRDD) {
		if (resolve(javaRDD)) {
			done(javaRDD);
		} else if (next != null) {
			next.support(javaRDD);
		} else {
			fail(javaRDD);
		}
	}


	protected abstract boolean resolve(JavaRDD<T> javaRDD);

	protected void done(JavaRDD<T> javaRDD) {
		System.out.println(javaRDD + " is resolved by " + this.getClass().getSimpleName());
	}

	protected void fail(JavaRDD<T> javaRDD) {
		System.out.println(javaRDD + " cannot ben resolved ");
	}
}
